﻿using Microsoft.EntityFrameworkCore;
using System;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Domain.Repository;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.Repository
{
    public class TaskRepository : RepositoryBase, ITaskRepository
    {
        public TaskRepository(WmsDbContext dbContext) : base(dbContext)
        {
        }

        /// <summary>
        /// 通过任务编号获取任务信息
        /// </summary>
        /// <param name="taskCode"></param>
        /// <returns></returns>
        public async Task<TaskPO?> GetTaskByTaskCode(string taskCode)
        {
            return await dbContext.Set<TaskPO>().Where(tk => tk.Code == taskCode).FirstOrDefaultAsync();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="trayBarcode"></param>
        /// <returns></returns>
        public async Task<TaskPO?> GetTaskByTrayBarcode(string trayBarcode)
        {
            return await dbContext.Set<TaskPO>().AsNoTrackingWithIdentityResolution().FirstOrDefaultAsync(entity => entity.Code == trayBarcode);
        }
    }
}
